home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / MACSHELL / MS1 / COMMANDS / EJECT.C < prev    next >
Text File  |  1992-12-02  |  5KB  |  187 lines

  1. /*
  2.  *    MacShell Source File
  3.  *
  4.  *    Copyright (c) 1989, 1990, 1991, 1992  Suick Bay Technologies.  All rights reserved.
  5.  *
  6.  *
  7.  *    RESTRICTIONS ON MacShell program and source code.
  8.  *
  9.  *    Ñ╩MacShell¬ is a product of Suick Bay Technologies and is provided for
  10.  *    restricted use by the owner of the CDROM "Disk to the future II".
  11.  *
  12.  *    Ñ╩No permission is granted for any commercial use without the written
  13.  *    consent of the Suick Bay Technologies.
  14.  *
  15.  *    Ñ╩No permission is granted for any redistribution of any kind use without
  16.  *    the written consent of the Suick Bay Technologies.
  17.  *
  18.  *    Ñ╩Permission is granted to use this for any personal noncommercial use.
  19.  *
  20.  *    Ñ╩You may not distribute source or executable code at all, nor may you 
  21.  *    distribute it with or within a commercial product without the written
  22.  *    consent of the Suick Bay Technologies.  Please send modifications to 
  23.  *    the author for inclusion in updates to the program.  Thanks.
  24.  *
  25.  *
  26.  *    MacShell¬ IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  27.  *    WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  28.  *    PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
  29.  *
  30.  *    SUICK BAY TECHNOLOGIES SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  31.  *    INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY MACSHELL
  32.  *    OR ANY PART THEREOF. 
  33.  *
  34.  *    In no event will Suick Bay Technologies be liable for any lost revenue
  35.  *    or profits or other special, indirect and consequential damages, even if
  36.  *    Suick Bay Technologies has been advised of the possibility of such damages.
  37.  *
  38.  *    Suick Bay Technologies can be reached at:
  39.  *    
  40.  *    8768 Cottonwood lane
  41.  *    Maple Grove, MN 55369
  42.  *    Voice: (612) 425-7025
  43.  *    AppleLink: D5233
  44.  *    
  45.  *
  46.  *    No parts of this software may be reproduced or stored in a
  47.  *    retrieval system or transmitted in any form, or any means,
  48.  *    electronic, mechanical, photocopying, recording or otherwise,
  49.  *    without the prior written permission of Suick Bay Technologies.
  50.  *    
  51.  *    Spread the word and not the disk.
  52.  *    
  53.  *    SPK 012290    :    Initial
  54.  */
  55.  
  56. #include    "SystemPub.h"
  57. #include    "Proc.h"
  58. #include    "Path.h"
  59. #include    "ShellPub.h"
  60.  
  61. /*******************************************************************/
  62.  
  63. #define        doUnmount        (**MyShell).Proc[ProcID].bflags.f0
  64. #define        EjectAbort        (**MyShell).Proc[ProcID].bflags.f1
  65.  
  66. void        EjectVol( WHandle ShellWh, int16 ProcID, char *argument )
  67. {
  68. int16            i;
  69. HVolumeParam    HPB;
  70. char            str[ 256 ];
  71. OSErr            err;
  72. ShellWindRec    **MyShell = (ShellWindRec **) (**ShellWh).thing;
  73.  
  74.     for( i = 1; i < 99; i++ )
  75.         {
  76.         if( UserAbort() )
  77.             {
  78.             EjectAbort = TRUE;
  79.             break;
  80.             }
  81.             
  82.         HPB.ioCompletion     = NULL;
  83.         HPB.ioNamePtr         = (StringPtr) str;
  84.         HPB.ioVRefNum         = 0;
  85.         HPB.ioVolIndex         = i;
  86.         
  87.         err = PBHGetVInfo( &HPB, FALSE );
  88.         
  89.         if( err == nsvErr || UserAbort())
  90.             break;
  91.             
  92.         if( err )
  93.             {
  94.             FileError( err );
  95.             break;
  96.             }
  97.         else
  98.             {
  99.             PtoCstr( str );
  100.             if( StrPatMatch( str, argument ) )
  101.                 {
  102.                 CtoPstr( str );
  103.                 err = Eject( str, HPB.ioVRefNum );
  104.                 
  105.                 if( !err && doUnmount )
  106.                     {
  107.                     err = UnmountVol( str, HPB.ioVRefNum );
  108.                     if( err )
  109.                         procPrintf( ShellWh, ProcID,
  110.                             "eject : can't unmount %ps (%d)\n",
  111.                             str, err );
  112.                     }
  113.                 else if( err )
  114.                     procPrintf( ShellWh, ProcID,
  115.                         "eject : can't eject %ps (%d)\n",
  116.                         str, err );
  117.                 }
  118.             }
  119.         }
  120. }
  121.  
  122. /*******************************************************************/
  123.  
  124. Boolean            DoEJECT( int16 ProcToken, WHandle ShellWh,
  125.                     int16 ProcID, char *string )
  126. {
  127. int16            i, argc;
  128. char            *cp, argument[ 256 ];
  129. ShellWindRec    **MyShell = (ShellWindRec **) (**ShellWh).thing;
  130.  
  131.     switch( ProcToken )
  132.         {
  133.         case    PROC_INIT    :
  134.             (**MyShell).Proc[ ProcID ].flags = TRUE;
  135.             break;
  136.             
  137.         case    PROC_TERM    :
  138.         case    PROC_BREAK    :
  139.             EjectAbort = TRUE;
  140.             /* Tell the shell that we're done */
  141.             SendOutToken( ShellWh, ProcID, PROC_BREAK );
  142.             /* Turn ourself off */
  143.             (**MyShell).Proc[ ProcID ].ProcActive = FALSE;
  144.             break;
  145.             
  146.         case    PROC_STDIN    :
  147.             if( (**MyShell).Proc[ ProcID ].flags )
  148.                 {
  149.                 (**MyShell).Proc[ ProcID ].flags = FALSE;        
  150.  
  151.                 argc = (**MyShell).Proc[ ProcID ].argc;
  152.                 doUnmount = FALSE;
  153.                 EjectAbort = FALSE;
  154.                 
  155.                 /* get arguments */
  156.                 for( i = 1; i < argc; i++ )
  157.                     {
  158.                     GetArgv( ShellWh, ProcID, i, argument );
  159.                     cp = argument;
  160.         
  161.                     if( *cp++ == '-' )
  162.                         while( *cp )
  163.                             switch( *cp++ )
  164.                                 {
  165.                                 case    'u'    :    /* unmount */
  166.                                     doUnmount = TRUE;
  167.                                     break;
  168.                                 }
  169.                     }
  170.  
  171.                 for( i = 1; i < argc; i++ )
  172.                     {
  173.                     GetArgv( ShellWh, ProcID, i, argument );
  174.                     EjectVol( ShellWh, ProcID, argument );
  175.                     ResetShellPWD( ShellWh );
  176.                     }
  177.  
  178.                 /* Tell the shell that we're done */
  179.                 SendOutToken(  ShellWh, ProcID, PROC_BREAK );
  180.                 
  181.                 /* Turn ourself off */
  182.                 (**MyShell).Proc[ ProcID ].ProcActive = FALSE;
  183.                 return( FALSE );
  184.                 }
  185.         }
  186. }
  187.